package store
import (
	"fmt"
	"encoding/json"
)
type Monster struct{
	Name string
	Age int
	Skill string
}

func Store() []byte{
	var monster =Monster{
		Name : "八戒",
		Age : 123,
		Skill : "吃我九齿钉耙",
	}
	str,err := json.Marshal(&monster) //str : []byte
	if err != nil{
		fmt.Println("序列化JSON格式失败！Error:",err)
	}
	return str
}

func ReStore(str []byte) Monster{
	var monster Monster
	err := json.Unmarshal(str,&monster) //反序列化接收参数是 data []byte, v interface{}  v是用来反序列化后要接收的结果
	if err != nil{
		fmt.Println("反序列化JSON格式失败！Error:",err)
	}
	fmt.Printf("反序列化JSON格式成功！Result:%v\n",monster)
	return monster
}